//
//  NSString+StringChangeTimeSting.m
//  WHPersonalData
//
//  Created by mac on 2018/3/8.
//  Copyright © 2018年 mac. All rights reserved.
//

#import "NSString+StringChangeTimeSting.h"

@implementation NSString (StringChangeTimeSting)
/*
 方法名:  将报送日期转换上传需要的时间格式
 @param  timeString
 @return 字符串
 */

+(NSString*)changeTimeFormatWith:(NSString*)timeString;
{
    NSMutableString*mutString =[[NSMutableString alloc]init];
    NSString* yaerString = [timeString substringToIndex:4];
    [mutString appendString:yaerString];
    
    if ([timeString containsString:@"周"]||[timeString containsString:@"W"])
    {
        //周
        if (timeString.length ==8)
        {
            NSString *weekSting = [timeString substringWithRange:NSMakeRange(6, 1)];
            [mutString appendString:@"0"];
            [mutString appendString:weekSting];
        }else
        {
            NSString *weekSting = [timeString substringWithRange:NSMakeRange(6, 2)];
            [mutString appendString:weekSting];
        }
        
    }else if ([timeString containsString:@"季"]||[timeString containsString:@"Q"])
    {
        //季
        NSString *qSting = [timeString substringWithRange:NSMakeRange(6, 1)];
        [mutString appendString:@"0"];
        [mutString appendString:qSting];
    }
    else if ([timeString containsString:@"上半"])
    {
        //上半年
        [mutString appendString:@"01"];
    }
    else if ([timeString containsString:@"下半"])
    {
        //下半年
        [mutString appendString:@"02"];
        
    }else if ([timeString containsString:@"日"]||[timeString containsString:@"d"])
    {
        //先以月做分割成两半（月字会去掉了）
        NSArray*array= [timeString componentsSeparatedByString:@"月"];
        NSString* monthString = array[0];
        if (monthString.length==6)
        {
            NSString *string = [monthString substringWithRange:NSMakeRange(5, 1)];
            [mutString appendString:@"0"];
            [mutString appendString:string];
            
        }else
        {
            NSString *string = [monthString substringWithRange:NSMakeRange(5, 2)];
            
            [mutString appendString:string];
        }
        
        NSString* dayString = array[1];
        if (dayString.length ==2)
        {
            NSString *string = [dayString substringWithRange:NSMakeRange(0, 1)];
            [mutString appendString:@"0"];
            [mutString appendString:string];
            
        }else
        {
            NSString *string = [dayString substringWithRange:NSMakeRange(0, 2)];
            
            [mutString appendString:string];
        }
        
    }else if ([timeString containsString:@"月"]||[timeString containsString:@"M"])
    {
        //月
        if (timeString.length ==7)
        {
            NSString *monthSting = [timeString substringWithRange:NSMakeRange(5, 1)];
            [mutString appendString:@"0"];
            [mutString appendString:monthSting];
        }else
        {
            NSString *monthSting = [timeString substringWithRange:NSMakeRange(5, 2)];
            [mutString appendString:monthSting];
        }
    }
    return mutString;
}



/*
 方法名:  时间转转时间(到秒)
 @param  timeString
 @return 字符串
 */

+(NSString *)stringTimeChangeStringTimeSeconds:(NSString *)stringTime
{
    //将传入时间转化成需要的格式
    NSDateFormatter *format=[[NSDateFormatter alloc]init];
    [format setDateFormat:@"yyyy年MM月dd日HH时mm分"];
    NSDate *fromdate=[format dateFromString:stringTime];
    NSDateFormatter *format1 = [[NSDateFormatter alloc] init];
    format1.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString *stringDate = [format1 stringFromDate:fromdate];
    return stringDate;
}

/*
 方法名:  时间转转时间(到时)
 @param  stringTime
 @return 字符串
 */

+(NSString *)stringTimeChangeStringTimeHour:(NSString *)stringTime
{
    //将传入时间转化成需要的格式
    NSDateFormatter *format=[[NSDateFormatter alloc]init];
    [format setDateFormat:@"yyyy年MM月dd日HH时"];
    NSDate *fromdate=[format dateFromString:stringTime];
    NSDateFormatter *format1 = [[NSDateFormatter alloc] init];
    format1.dateFormat = @"yyyyMMddHH";
    NSString *stringDate = [format1 stringFromDate:fromdate];
    return stringDate;
}
@end
